from numpy import array
import pandas as pd
import numpy as np
import cvxpy as cp
#挥发分&价格
huifafen_zhujiaomei = 21.0773646209386
huifafen_feimei = 27.3091472868217
huifafen_13jiaomei = 32.3345192307693
huifafen_qimei = 33.8875694444444
huifafen_shoumei = 13.5580487804878
price_zhujiaomei = 1752.95152356286
price_feimei = 1974.69294632063
price_13jiaomei = 1543.16230442389
price_qimei = 1349.10154518214
price_shoumei = 1384
#年度方案&预算方案
year_percentage_zhujiaomei = 39.9009619556274
year_percentage_feimei = 19.0977364869919
year_percentage_13jiaomei = 14.5609861915234
year_percentage_qimei = 21.5624672740601
year_percentage_shoumei = 4.8778480917972
month_budget_percentage_zhujiaomei = 39.8565305527089
month_budget_percentage_feimei = 18.561266241295
month_budget_percentage_13jiaomei = 14.9640578365885
month_budget_percentage_qimei = 20.7192920777637
month_budget_percentage_shoumei = 5.89885329164392
#调整方案
month_adjust_percentage_zhujiaomei = 43
month_adjust_percentage_feimei = 16
month_adjust_percentage_13jiaomei = 15
month_adjust_percentage_qimei = 18
month_adjust_percentage_shoumei = 8
#干煤量
ganmeiliang = 61.05
year_price_peihemei = (price_zhujiaomei * year_percentage_zhujiaomei + price_feimei * year_percentage_feimei + price_13jiaomei * year_percentage_13jiaomei + price_qimei * year_percentage_qimei + price_shoumei * year_percentage_shoumei) / 100
year_huifafen_peihemei = (huifafen_zhujiaomei * year_percentage_zhujiaomei + huifafen_feimei * year_percentage_feimei + huifafen_13jiaomei * year_percentage_13jiaomei + huifafen_qimei * year_percentage_qimei + huifafen_shoumei * year_percentage_shoumei) / 100
year_theory_chengjiaolv = 97 - year_huifafen_peihemei * 5 / 6 - 0.13
year_production_jiaotan = year_theory_chengjiaolv * ganmeiliang / 100
year_COG_generation = (9.37 * year_huifafen_peihemei + 66.7) * ganmeiliang/24/30 + 0.03

month_budget_price_peihemei = (price_zhujiaomei * month_budget_percentage_zhujiaomei + price_feimei * month_budget_percentage_feimei + price_13jiaomei * month_budget_percentage_13jiaomei + price_qimei * month_budget_percentage_qimei + price_shoumei * month_budget_percentage_shoumei) / 100
month_budget_huifafen_peihemei = (huifafen_zhujiaomei * month_budget_percentage_zhujiaomei + huifafen_feimei * month_budget_percentage_feimei + huifafen_13jiaomei * month_budget_percentage_13jiaomei + huifafen_qimei * month_budget_percentage_qimei + huifafen_shoumei * month_budget_percentage_shoumei) / 100
month_budget_theory_chengjiaolv = 97 - month_budget_huifafen_peihemei * 5 / 6 - 0.13
month_budget_production_jiaotan = month_budget_theory_chengjiaolv * ganmeiliang / 100
month_budget_COG_generation = (9.37 * month_budget_huifafen_peihemei + 66.7) * ganmeiliang/24/30 + 0.03

month_adjust_price_peihemei = (price_zhujiaomei * month_adjust_percentage_zhujiaomei + price_feimei * month_adjust_percentage_feimei + price_13jiaomei * month_adjust_percentage_13jiaomei + price_qimei * month_adjust_percentage_qimei + price_shoumei * month_adjust_percentage_shoumei) / 100
month_adjust_huifafen_peihemei = (huifafen_zhujiaomei * month_adjust_percentage_zhujiaomei + huifafen_feimei * month_adjust_percentage_feimei + huifafen_13jiaomei * month_adjust_percentage_13jiaomei + huifafen_qimei * month_adjust_percentage_qimei + huifafen_shoumei * month_adjust_percentage_shoumei) / 100
month_adjust_theory_chengjiaolv = 97 - month_adjust_huifafen_peihemei * 5 / 6 - 0.13
month_adjust_production_jiaotan = month_adjust_theory_chengjiaolv * ganmeiliang / 100
month_adjust_COG_generation = (9.37 * month_adjust_huifafen_peihemei + 66.7) * ganmeiliang/24/30 + 0.03

increase_production_jiaotan = month_adjust_production_jiaotan - month_budget_production_jiaotan
increase_culiaoliang = increase_production_jiaotan * 0.115
decrease_COG_generation = (month_budget_COG_generation - month_adjust_COG_generation) * 30 * 24
increase_price_peihemei = month_adjust_price_peihemei - month_budget_price_peihemei
decrease_waigoujiao = increase_production_jiaotan * 0.835 / 0.8
increase_purchase_cujiao = decrease_waigoujiao * 0.2 - increase_culiaoliang
decrease_power_COG = decrease_COG_generation * 1.9
increase_cost_peihemei = increase_price_peihemei * ganmeiliang
price_waigoujiao = 2407.41
price_waigoujiaofen = 1477.14
price_tianranqi = 2.7
price_waigoudian = 0.72
price_fadianmei = 807
price_COG = 1.39
decrease_cost_waigoujiao = -decrease_waigoujiao * price_waigoujiao
increase_cost_cujiao = increase_purchase_cujiao * price_waigoujiaofen

total_cost_liantie = increase_cost_peihemei + decrease_cost_waigoujiao + increase_cost_cujiao
#天然气发电
#与天然气相比，焦炉煤气热值仅为其 1/2，因此天然气的增量需要焦炉煤气的一半。
increase_tianranqi = decrease_COG_generation / 2
influnce_cost1 = increase_tianranqi * price_tianranqi
#煤炭发电
# 发电煤耗420（克/度）
increase_fadianmei = decrease_power_COG * 420 / 100
influnce_cost2 = increase_fadianmei * price_fadianmei / 10000
#外购电替代
increase_waigoudian = decrease_power_COG
influnce_cost3 = increase_waigoudian * price_waigoudian

total_cost1 = total_cost_liantie + influnce_cost1
total_cost2 = total_cost_liantie + influnce_cost2
total_cost3 = total_cost_liantie + influnce_cost3

# a11
# a12
# c1=(-9.37*主焦煤挥发分/100*配煤量/24/30)*30*24*
# MIN(1/2*天然气价格,1.9*420/100*发电煤价格/10000,1.9*外购电价)
# +主焦煤价格/100*配煤量/0.883-(-主焦煤挥发分/100*5/6*配煤量/100)*((0.835/0.8*0.2-0.115)*外购焦粉价格-0.835/0.8*外购焦价格)
month_adjust_percentage_zhujiaomei_max = 50
month_adjust_percentage_feimei_max = 20
month_adjust_percentage_13jiaomei_max = 20
month_adjust_percentage_qimei_max = 25
month_adjust_percentage_shoumei_max = 10
b1 = month_adjust_percentage_zhujiaomei_max
b2 = month_adjust_percentage_feimei_max
b3 = month_adjust_percentage_13jiaomei_max
b4 = month_adjust_percentage_qimei_max
b5 = month_adjust_percentage_shoumei_max
c11 = ganmeiliang * price_zhujiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang / 2 * price_tianranqi) * huifafen_zhujiaomei / 100
c12 = ganmeiliang * price_feimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang / 2 * price_tianranqi) * huifafen_feimei / 100
c13 = ganmeiliang * price_13jiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang / 2 * price_tianranqi) * huifafen_13jiaomei / 100
c14 = ganmeiliang * price_qimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang / 2 * price_tianranqi) * huifafen_qimei / 100
c15 = ganmeiliang * price_shoumei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang / 2 * price_tianranqi) * huifafen_shoumei / 100

c21 = ganmeiliang * price_zhujiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * 420 / 100 * price_fadianmei / 10000) * huifafen_zhujiaomei / 100
c22 = ganmeiliang * price_feimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * 420 / 100 * price_fadianmei / 10000) * huifafen_feimei / 100
c23 = ganmeiliang * price_13jiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * 420 / 100 * price_fadianmei / 10000) * huifafen_13jiaomei / 100
c24 = ganmeiliang * price_qimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * 420 / 100 * price_fadianmei / 10000) * huifafen_qimei / 100
c25 = ganmeiliang * price_shoumei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * 420 / 100 * price_fadianmei / 10000) * huifafen_shoumei / 100

c31 = ganmeiliang * price_zhujiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * price_waigoudian) * huifafen_zhujiaomei / 100
c32 = ganmeiliang * price_feimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * price_waigoudian) * huifafen_feimei / 100
c33 = ganmeiliang * price_13jiaomei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * price_waigoudian) * huifafen_13jiaomei / 100
c34 = ganmeiliang * price_qimei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * price_waigoudian) * huifafen_qimei / 100
c35 = ganmeiliang * price_shoumei / 100 + ((5 / 6 * ganmeiliang / 100 * 0.115 - 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * 0.2) * price_waigoujiaofen + 5 / 6 * ganmeiliang / 100 * 0.835 / 0.8 * price_waigoujiao - 9.37 * ganmeiliang * 1.9 * price_waigoudian) * huifafen_shoumei / 100


c = array([c11, c12, c13, c14, c15])
c = array([c21, c22, c23, c24, c25])
c = array([c31, c32, c33, c34, c35])
e1 = array([[1, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 1, 0, 0],
            [0, 0, 0, 1, 0],
            [0, 0, 0, 0, 1]])  # 定义不等式约束矩阵
f1 = array([b1, b2, b3, b4, b5])
e2 = array([[1, 1, 1, 1, 1]])
f2 = array([100])
x = cp.Variable(5)
obj = cp.Minimize(c @ x)
cons = [e1 @ x <= f1, e2 @ x == f2, x >= 0]
prob = cp.Problem(obj, cons)
prob.solve(solver='GLPK_MI', verbose=True)
print("最优初始值为:", prob.value)
print("最优初始解为：\n", x.value)

chushi_x11 = abs(x.value[0])
chushi_x12 = abs(x.value[1])
chushi_x13 = abs(x.value[2])
chushi_x14 = abs(x.value[3])
chushi_x15 = abs(x.value[4])





print('finish')